package com.xinz.srmi;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

public interface RemoteInvokeListener{
	void onBeginInvok(Method method, Object[] args);

	void onInvokException(Object header, Throwable e);

	void onInvokSuccess(Object header, Object result);
	
	
	public static  class Abstract implements RemoteInvokeListener{

		@Override
		public void onBeginInvok(Method method, Object[] args) {
			
		}

		@Override
		public void onInvokException(Object object, Throwable e) {
			
		}

		@Override
		public void onInvokSuccess(Object object, Object result) {
			
		}

		
	}
	
	public static class ListListener implements RemoteInvokeListener{
		List<RemoteInvokeListener> listeners = new ArrayList<RemoteInvokeListener>();
		
		
		@Override
		public void onBeginInvok(Method method, Object[] args) {
			for(int i=0;i<listeners.size();i++){
				listeners.get(i).onBeginInvok(method, args);
			}
		}

		@Override
		public void onInvokException(Object object, Throwable e) {
			for(int i=0;i<listeners.size();i++){
				listeners.get(i).onInvokException(object, e);
			}
		}

		@Override
		public void onInvokSuccess(Object object, Object result) {
			for(int i=0;i<listeners.size();i++){
				listeners.get(i).onInvokSuccess(object, result);
			}
		}

		public void add(RemoteInvokeListener filter) {
			listeners.add(filter);
		}
	}

	
	
	
}